#include-once
#Include <GuiToolBar.au3>
#Include <GuiListView.au3>
#Include <File.au3>
#include <WinAPI.au3>
#Include <GuiTreeView.au3>
#include <Array.au3>
#include <Excel.au3>
#Include <ScreenCapture.au3>
#Include <SendMessage.au3>
#include <Array.au3>

;#AutoItSetOption("MustDeclareVars", 1)   ;Variables must be pre-declared.
;Define the Result String
Global Const $sPass = "PASS"
Global Const $sFaile = "____FAIL: "
Global Const $sRootFolder = "C:\AutomationTest\"
Global Const $sDiskCPath = 'C:\'  
Global Const $sFunctionNameTXT = 'C:\FunctionName.txt'
Global Const $sOSVersion = @OSVersion   ;Return "WIN_7" or "WIN_XP" or "WIN_2008R2" etc.
Global Const $PMFolder = @MyDocumentsDir & "\My PageManager\"   ;My PageManager folder path.
Global Const $sPCodeIniPath =  GetSettingIniPath()  
Global Const $iTestIDCoulmn = 6   ;The number of test ID in xls.
Global Const $iTestPurposeCoulmn = 7   ;The number of test purpose in xls.
Global Const $iFirstStepCoulmn = 8   
Global Const $iSecondStepCoulmn = 9   
Global Const $iThirdStepCoulmn = 10   
Global Const $iFourthStepCoulmn = 11  
Global Const $sTestPurpose = 'Test Purpose'   ;String in xls.
Global Const $sFirstClass = 'First Class'   ;String in xls.
Global Const $sSecondClass = 'Second Class'   ;String in xls.
Global Const $sThirdClass = 'Third Class'   ;String in xls.
Global Const $sFourClass = 'Four Class'   ;String in xls.
Global Const $sFiveClass = 'Five Class'   ;String in xls.
Global Const $sExpectedResult = 'Expected Result'   ;String in xls.
Global Const $sTotalTestCaseNumber =  "Total Test Case Of "   ;The string in log file.
Global Const $sAutomationTestCaseNumber  =  "Total Automation Test Case Of "   ;The string in log file.
Global Const $sHTestCaseNumber  =  "Total H Test Case Of "   ;The string in log file.
Global Const $sMTestCaseNumber  =  "Total M Test Case Of "   ;The string in log file.
Global Const $sLTestCaseNumber  =  "Total L Test Case Of "   ;The string in log file.
Global Const $Double_ByteTxtPath = "C:\AutomationTest\Double_Byte.txt"
Global Const $AUTOAMTIONTEST_FOLDER_PATH = "C:\AutomationTest\"
Global Const $COMMON_SAMPLES_FOLDER_PATH = "C:\AutomationTest\CommonSamples\"

Global Const $sExcelObject =  GetExcelObject()  
Global $oExcel = $sExcelObject[1]   ;Get STD escel object.

Global Const $sTempTXTPath = "c:\Temp.txt"    ;Temp txt to record which test case has been execute.(record with test case ID)
Global Const $sTempTXTPath_ = "c:\Temp_.txt"   ;Temp txt to record which test case should be execute.(record with test case ID)
Global Const $sStepCheckPointINIPath = "c:\TestCaseStepAndCheckPoint.ini"   ;TestCaseStepAndCheckPoint.ini record the test case step in automation test and check point.
Global Const $sProcessName = "Prestopm.exe"
Global Const $sCompareScreenCaptureFile = "Please compare the screen capture file!" 
Global $sStepAndCheckPoint   ;Describe the progress of automation test.
Global $sErrorFunction = ""
Global $sFunctionName = ""
Global $bIsTestCasePassed
Global $sMyDocuments = "My Documents"
Global $sErrorDescribetion
Global $sFunctionName_CompareFile = 'AutoIT script occurred an error in function ( "Common_CompareFile" ).Plese execuete this test case by manual.'
Global Const $CompareScreenCapture = "Please check the screen capture file." & @CRLF 
Global Const $MunalExecuteTestCase = "Please execute test case by munal."

Local $sLONGEST_FILE_NAME = '1111111111111111111110000001111111111111111111111100000011111111111111111111110000001111111111111110000001111ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss1111111111111111111111111111aqwer'

;App Bar Define
Global Const $nMaxIconCount  	= 17
Global Const $nIconWidth 		= 60


;Section Nmae:
Global Const $sSectionBasicInfo					= 'BasicInfo'
Global Const $sSectionOthers					= 'Others' 
Global Const $sSectionAppBar					= 'Application Bar'
Global Const $sSectionBackupRestore				= 'Backup and Restore'
Global Const $sSectionCommonCtrlInfo			= 'CommonCtrlInfo' 
Global Const $sSectionNamePageView 				= "Page view"
Global Const $sSectionNameThumbanil 			= "Thumbnail view"
Global Const $sSectionNameFax 					= "FAX"
Global Const $sSectionNameOCR					= "OCR"
Global Const $sSectionNameSaveAs				= "Save As"
Global Const $sSectionNameDocumentPallet		= "Document Pallet"
Global Const $sSectionNameFTP					= "FTP"
Global Const $sSectionNameTreeView				= "TreeView"
Global Const $sSectionNameFormDispatching		= "Form Dispatching"
Global Const $sSectionNamePrint					= "Print"
Global Const $sSectionNameFormOthers			= "Others"
Global Const $sSectionNameScan			        = "Scan"
Global Const $sSectionNameProformance		    = "Performane"
Global Const $sSectionNameScanButton		    = "Scan Button"
Global Const $sCommonWndClass                   = '[CLASS:#32770]'

;Function Name by Excel Sheet
Global Const $sAppBarFunctionName 				= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'AppBar')
Global Const $sBackupRestoreFunctionName 		= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'BackupRestore')
Global Const $sCloudFunctionName 				= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'Cloud')
Global Const $sDocumentPalletFunctionName 		= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'DocumentPallet')
Global Const $sFaxFunctionName 					= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'Fax')
Global Const $sFindFunctionName 				= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'Find')
Global Const $sScanFunctionName 				= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'Scan')
Global Const $sFormDispatchingFunctionName 		= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'FormDispatching')
Global Const $sSaveAsFunctionName 				= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'SaveAs')
Global Const $sThumbanilViewFunctionName 		= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'ThumbanilView')
Global Const $sScanButtonFunctionName 			= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'ScanButton')
Global Const $sOCRFunctionName 					= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'OCR')
Global Const $sPageViewerFunctionName 			= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'PageViewer')
Global Const $sPrintFunctionName 				= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'Print')
Global Const $sTreeViewFunctionName 			= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'TreeView')
Global Const $sPerformaneFunctionName 			= ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'Performane')


;Key Value:BasicInfo
Global Const $sPMVersion 						 			 = PMVerSion()
Global Const $bPageViewType						 			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'PageViewType'))
Global Const $bisHasCloudStorageTreeview					 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'isHasCloudStorageTreeview'))
Global Const $sPageViwerWindowClass 			  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViwerWindowClass')
Global Const $sPreviewWnd           			  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PreviewWnd')
Global Const $sPreviewWndScroolBar        		         	 = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PreviewWndScroolBar')
Global Const $PageViwerImaageView 			  			     = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViwerImaageView')
Global Const $PageViwerDocView 			  			         = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViwerDocView')
Global Const $PageViwerHTMLView 			  			     = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViwerHTMLView')
Global Const $PageViwerPDFView 			     			     = ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViwerPDFView')
Global Const $sPageViewerToolBar 				  			 = Number( ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViewerToolBar'))
Global Const $sPageViewerTaskPanel 				  			 = Number( ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViewerTaskPanel'))
Global Const $iDelDB 							  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'DelDB') 
Global Const $sComputer_DiskVolumeName 			  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionOthers, 'Computer_DiskVolumeName') 
Global Const $sDiskC_DiskVolumeName 			  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionOthers, 'DiskC_DiskVolumeName') 
Global Const $sTreeViewCtrInfo 					  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'TreeView')
Global Const $sQinckLinksCtrInfo				  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'QuickLinks')
Global Const $sThumbnailViewCtrInfo 			  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'ThumbnailView')
Global Const $sMenuCtrInfo 						  			 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'Menu')
Global Const $sSwicthToListViewButtonCtrInfo 	  			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'SwicthToListViewButtonInToolbar'))
Global Const $sSwicthToThumbnailViewButtonCtrInfo 			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'SwicthToThumbnailViewButtonInToolbar'))
Global Const $sSwicthToTitleViewButtonInCtrInfo   			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'SwicthToTitleViewButtonInToolbar'))
Global Const $sStackButtonInToolbarCtrInfo 		  			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'StackButtonInToolbar'))
Global Const $sOCRButtonInToolbarCtrInfo		  			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'OCRButtonInToolbar'))
Global Const $sPageViewCtrInfo							     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'PageView'))
Global Const $sPageViewButtonInToolbarCtrInfo	 			 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'PageViewButtonInToolbar'))
Global Const $sSaveAsButtonInToolbarCtrInfo 		    	 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'SaveAsButtonInToolbar')
Global Const $sPreferencesButtonInToolbarCtrInfo             = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'PreferencesButtonInToolbar'))
Global Const $sSaveAsTitle 					            	 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'SaveAsTitle')
Global Const $sPreferencesDialogTitle            			 = ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'PreferencesDialogTitle')
Global Const $sPreferencesTabControl 	            		 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'PreferencesTabControl'))
Global Const $iNonUICheckBox			                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'NonUICheckBox'))
Global Const $iPreifxEditBox			                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'PreifxEditBox'))
Global Const $iOKButton			                             = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'OKButton'))
Global Const $sSelectSourceDlg	                             = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'SelectSourceDlg')
Global Const $sScannerDriverNameInSelectSource	             = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScannerDriverNameInSelectSource')
Global Const $sScanningProgressBarDlgTextWIA	             = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanningProgressBarDlgTextWIA')
Global Const $sScannerDriverNameInSelectSourceWIA	         = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScannerDriverNameInSelectSourceWIA')
Global Const $ScanButtonInToolbar			                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanButtonInToolbar'))
Global Const $sScanningProgressBarDlgTitle	                 = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanningProgressBarDlgTitle')
Global Const $sScanningProgressBarDlgTitleWIA	             = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanningProgressBarDlgTitleWIA')
Global Const $sScannerShowUIDlg	                             = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScannerShowUIDlg')
Global Const $iScannerShowUIScanButtonID		             = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScannerShowUIScanButtonID'))
Global Const $ScanToMyPagemanagerFolderBtnInScanSetting	     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanToMyPagemanagerFolderBtnInScanSetting'))
Global Const $iScanToActiveFolderBtnInScanSetting		     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanToActiveFolderBtnInScanSetting'))
Global Const $iSaveSettingsBtnInInScanSetting	             = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'SaveSettingsBtnInInScanSetting'))
Global Const $iLoadSettingsBtnInInScanSetting	             = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'LoadSettingsBtnInInScanSetting'))
Global Const $sDoubleByteFileName                            = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'DoubleByteFileName')
Global Const $iDocumentTypeCombox			                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'DocumentTypeCombox'))
Global Const $iColorModeCombox	     		                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ColorModeCombox'))
Global Const $iScanSizeCombox	     		                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ScanSizeCombox'))
Global Const $iDPICombox	     		                     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'DPICombox'))
Global Const $iSaveAsTypeCombox	     		                 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'SaveAsTypeCombox'))
Global Const $iEnableDocumentFeederCheckbox    		         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'EnableDocumentFeederCheckbox'))
Global Const $iDescreenCheckbox 	             	         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'DescreenCheckbox'))
Global Const $iAutocropCheckbox 	             	         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'AutocropCheckbox'))
Global Const $iAutocropCombox	                 	         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'AutocropCombox'))
Global Const $iContinueScanCheckbox	               	         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ContinueScanCheckbox'))
Global Const $iBrightnessEditbox	                 	     = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'BrightnessEditbox'))
Global Const $iContrastEditbox	                 	         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ContrastEditbox'))
Global Const $iThresholdEditbox                  	         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'ThresholdEditbox'))
Global Const $sSelectSourceListBox                           = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScan, 'SelectSourceListBox')
Global Const $iPMSBButtonInToolbar					    	 = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameScanButton, 'PMSBButtonInToolbar'))
Global Const $sPMSBBWndTitle				    	    	 = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScanButton, 'PMSBBWndTitle')
Global Const $sPMSBToolBar	   			    	    	     = ReadIniKeyValue($sPCodeIniPath, $sSectionNameScanButton, 'PMSBToolBar')
Global Const $iApplicationBarIconCount						 = Number(ReadIniKeyValue($sPCodeIniPath, 'Application Bar', 'IconCount'))
Global Const $sPMToolBar	   			    	    	     = ReadIniKeyValue($sPCodeIniPath, 'BasicInfo', 'PMToolBar')
Dim Const $sOCRLableIndex			                         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameOCR, 'OCRLableIndex'))
Dim Const $sOCRLanguageListBox		                         = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameOCR, 'OCRLanguageListBox'))
Global Const $sDoubleByteStrForTest                              = ReadIniKeyValue($sPCodeIniPath, 'Others', 'DoubleByteString')

Global $sExecuteTestCaseLevel_ 					  =  ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'ExecuteTestCaseLevel')   ;Key value in P-Code.ini 
Global $sMessageTitle 							  =  ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'MessageTitle') 
Global $sAllMessageTitle						  =  ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'AllMessageTitle') 
Global $sMyPageManagerSampleFolder 				  =  ReadIniKeyValue($sPCodeIniPath, $sSectionCommonCtrlInfo, 'MyPageManagerSampleFolder') 


Global $sPageViewerMessageTitle 				  =  ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViewerMessageTitle') 
;Global $sPageViewerAnnotation 					  =  Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViewerAnnotation'))
Global $sPageViewerAnnotation 					  =  ReadIniKeyValue($sPCodeIniPath, $sSectionNamePageView, 'PageViewerAnnotation')


Global $sExecuteTestCaseLevel 					  = StringUpper($sExecuteTestCaseLevel_)

Global $sOCR_LANGUAGES_SMAPLE_PATH                = 'C:\AutomationTest\CommonSamples\OCR_Languages\'                

Global $DllFolderPath = "C:\AutomationTest\Dll\"
Global $ExeFolderPath = "C:\AutomationTest\Script\"
Global $dllPath = $ExeFolderPath & "ImageOperate.dll"
 
Global $Dll1 = $DllFolderPath & "Ism.dll"
Global $Dll2 = $DllFolderPath & "ImageOperate.dll"
Global $Dll3 = $DllFolderPath & "FioAll32.dll"
Global $Dll4 = $DllFolderPath & "Fiotif32.dll"

Global $sPagemanagerAlertTitle                                = 'Presto! PageManager' 
Global $sPagemanagerAlertTitle2                               = 'PageManager' 
Global $sPagemanagerAlertMsg                                  = 'OK' 

Global $COMMON_TEST_FOLDER_PATH            = 'C:\AutomationTest\0TestFolder\'
Global $COMMON_SAMPLE_IN_PAGEVIEWER_FLODER = 'C:\AutomationTest\PageViewer\Sample\'

Dim Const $Saveto_1[17] 				= ["BMP","PCX","TIFFUncompressed","TIFFPackbits","TIFFG3","TIFFG4","TIFFMultiplePage","JPEG","PCT","Targa","Targarle","PNG","PSD","GIF","TXT","RTF","HTML"]
Dim Const $SaveFormat_1[17] 			= ["BMP(*.BMP)","PaintBrush(*.PCX)","TIFF-uncompressed(*.TIF)","TIFF-packbits(*.TIF)","TIFF-G3 compression(*.TIF)","TIFF-G4 compression(*.TIF)","TIFF-multiple page(*.TIF)","JPEG(*.JPG)","PICT(*.PCT)","Targa(*.TGA)","Targa-rle(*.TGA)","PNG(*.PNG)","Photoshop(*.PSD)","GIF(*.GIF)","Text(*.TXT)","Rich Text Format(*.RTF)","HTML(*.HTM)"]
Dim Const $FileFormat_1[17] 			= [".bmp",".pcx",".tif",".tif",".tif",".tif",".tif",".jpg",".pct",".tga",".tga",".png",".psd",".gif",".txt",".rtf",".htm"]

Func Common_ClosePMAndWriteTheRecord($hPMHandle,$TestCaseID)  
	Common_Close_PM($hPMHandle) 
	Common_WiteTestCaseExecuteRecode($sTempTXTPath,$TestCaseID)
EndFunc	


Func Common_DllCopy()
	Local $FileList = _FileListToArray($DllFolderPath)

	If @error <> 1 And @error <> 4 Then
		For $i=1 To $FileList[0]
			FileCopy($DllFolderPath&$FileList[$i],$ExeFolderPath&$FileList[$i],1)
		Next
	EndIf
	
EndFunc

Func Common_DllRemove()
	Local $FileList1 = _FileListToArray($DllFolderPath)
	If @error <> 1 And @error <> 4 Then
		For $j=1 To $FileList1[0]
			FileDelete($ExeFolderPath&$FileList1[$j])
		Next
	EndIf	
EndFunc


Func Common_GetImageDPI ($file)
	
	$dll = DllOpen($dllPath)
	$result = DllCall($dll, "int","Auto_GetImageDPI", "str",$file)
	DllClose($dll)

	If Not @error Then
		Return $result[0]
	Else
		Return @error
	EndIf
	DllClose($dll)

EndFunc

Func Common_SelectAllItems($hThumbnailView)
	;Select All items.
	_GUICtrlListView_ClickItem($hThumbnailView, 0, "left", True) 
	Sleep(400)
	Send('!e')
	Sleep(500)
	Send('s')
	Sleep(500)
	Send('s')
	Sleep(500)
	Send('{ENTER}')
	Sleep(800)
EndFunc

Func Common_GetImageType ($file)
	$dll = DllOpen($dllPath)
	$result = DllCall($dll, "int","Auto_GetImageType", "str",$file)
	DllClose($dll)
	
	If Not @error Then
		Local $msg
		Switch $result[0]
			Case 0
				$msg = "BlackWhite"
			Case 1 To 3
				$msg = "Color"
			Case 4 To 5
				$msg = "Gray"
			Case 6 To 9
				$msg = "Color"
			Case 10
				$msg = "Gray"
			Case Else
				$msg = "Unknow"
		EndSwitch
		;MsgBox(0, Default, $msg)
		Return $msg
	Else
		Return @error
	EndIf
	DllClose($dll)
EndFunc

Func Common_GetImageHeight ($file)
	$dll = DllOpen($dllPath)
	$result = DllCall($dll, "int","Auto_GetImageHeight", "str",$file)
	DllClose($dll)
	
	If Not @error Then
		Return $result[0]
	Else
		Return @error
	EndIf
	DllClose($dll)
EndFunc


Func Common_GetImageWidth ($file)
	$dll = DllOpen($dllPath)
	$result = DllCall($dll, "int","Auto_GetImageWidth", "str",$file)
	DllClose($dll)
	
	If Not @error Then
		Return $result[0]
	Else
		Return @error
	EndIf
	DllClose($dll)
EndFunc

Func Common_ScanImageCompare_($file,$color,$dpi)
	If $color = Common_GetImageType ($file) Then
		If $dpi = Common_GetImageDPI ($file) Then	
			Return 1
		Else
			Return -2
		EndIf	
	Else
		Return -1
	EndIf
EndFunc

Func Common_ScanImageCompare($file,$color,$dpi,$width,$hight)
	If $color = Common_GetImageType ($file) Then
		If $dpi = Common_GetImageDPI ($file) Then
			If $width = Common_GetImageWidth ($file) Then
				If $hight = Common_GetImageHeight ($file) Then
					Return 1
				Else
					Return -4
				EndIf
			Else
				Return -3
			EndIf	
		Else
			Return -2
		EndIf	
	Else
		Return -1
	EndIf
EndFunc


Func GetLayerPath($strPath)   ;Modify
	Local $array = StringSplit($strPath, '\', 1)
	If @error Then
		Return False
	EndIf
	Local $strTemp = $array[$array[0]]
	Local $len = StringLen($strTemp)
	Local $strLoalAppdataPath = StringTrimRight($strPath, $len)
	Return $strLoalAppdataPath
EndFunc

Func Common_ReproduceRunWithIni($sFunctionName,$TestCaseID)  
	;Get INI Path
	Local $strPath = GetLayerPath(@AppDataDir)	
	Local $strINIPath = $strPath&"Local\AutoTestingResultTool\ReProduce.ini"
	;Auto reproduce
	If FileExists($strINIPath) Then
		Local $bRun =  IniRead ($strINIPath, $sFunctionName, $TestCaseID,0)
		If $bRun = 1 Then
			Return True
		EndIf
		Return False
	EndIf
	Return True
EndFunc

Func RefreshShellTrayToolbar() 
	Local $hShell_TrayToolbar, $aShellTrayToolbarPos, $xShell_TrayToolbar, $yShell_TrayToolbar 
	Local $iMsg_WM_MOUSEMOVE   = 0x00000200 
	$hShell_TrayToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32; INSTANCE:1]") 
	$aShellTrayToolbarPos = ControlGetPos ("[Class:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32; INSTANCE:1]") 
	If IsArray($aShellTrayToolbarPos) Then 
		If $aShellTrayToolbarPos[2] >= 2 And $aShellTrayToolbarPos[3] >= 2 Then 
			$xShell_TrayToolbar = $aShellTrayToolbarPos[2] 
			$yShell_TrayToolbar = $aShellTrayToolbarPos[3] 
			For $i = 0 To $xShell_TrayToolbar - 1 Step 1 
				_SendMessage($hShell_TrayToolbar, $iMsg_WM_MOUSEMOVE, 0, Dec(Hex($yShell_TrayToolbar/2, 4)&Hex($i, 4) ), 0, "wparam", "lparam", "Int") 
			Next 
		EndIf 
	EndIf 
EndFunc 


Func Common_WriteCurrentFunctionNameToTempTXT($sFunctionName)
	If FileExists($sFunctionNameTXT) Then
		FileDelete($sFunctionNameTXT)
	EndIf
	
	Local $file = FileOpen($sFunctionNameTXT, 1)
	If $file = -1 Then
		MsgBox(0, "Error", "Unable to open file." & $sFunctionNameTXT)
		Exit
	EndIf
	
	FileWriteLine ($file, $sFunctionName)
	
	FileClose($file)
EndFunc

Func WriteReproduceResultIni($strCategory,$strTestCaseID,$strResult)
	;Get INI Path
	Local $strPath = GetLayerPath(@AppDataDir)
	Local $strINIPath = $strPath&"Local\AutoTestingResultTool\ReProduceResult.ini"
	;Write the Result to ReProduceResult.ini
	IniWrite($strINIPath, $strCategory,$strTestCaseID,$strResult)
EndFunc

Func Common_InitializeStatus()   

	If WinExists("[CLASS:#32770]", "FolderView") Then
		WinActivate("[CLASS:#32770]", "FolderView")
		Sleep(300)
		Send('{ESC}')
		Sleep(1000)
	EndIf

	FileRecycleEmpty()
	
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd

	While ProcessExists('NetGroup.exe')
		ProcessClose('NetGroup.exe')
	WEnd
	
	While ProcessExists('Scan Central.exe')
		ProcessClose('Scan Central.exe')
	WEnd	

	While ProcessExists('PageViewer.exe')
		ProcessClose('PageViewer.exe')
	WEnd

	If FileExists("C:\MSOCache") Then
		DirRemove("C:\MSOCache", 1)
		Sleep(2000)
	EndIf
	
	While ProcessExists('hh.exe')
		ProcessClose('hh.exe')
	WEnd
	
	While ProcessExists('BCompare.exe')
		ProcessClose('BCompare.exe')
	WEnd	
	
	While ProcessExists('notepad++.exe')
		ProcessClose('notepad++.exe')
	WEnd	

	While ProcessExists('notepad.exe')
		ProcessClose('notepad.exe')
	WEnd	
	
	While WinExists('Save As')
		WinClose('Save As')
	WEnd	
	
	WinKill ( "[CLASS:Photo_Lightweight_Viewer]" )
	
	CopySamplesToMyPagemanagerFolder()

	RefreshShellTrayToolbar() 
	
	DeleteDesktopFiles()
	
	Local $FileList=_FileListToArray(@MyDocumentsDir)
	If @Error Then Return
	For $i = 1 to $FileList[0]
		If StringInStr($FileList[$i], 'My PageManager') Or StringInStr($FileList[$i], 'desktop.ini') Or StringInStr($FileList[$i], 'My Music') Or StringInStr($FileList[$i], 'My Pictures') Or StringInStr($FileList[$i], 'My Videos') Then
		Else
			FileDelete(@MyDocumentsDir & '\' & $FileList[$i])
			DirRemove(@MyDocumentsDir & '\' & $FileList[$i])
		EndIf
	Next
	
	If WinExists("[CLASS:#32770]", "&Yes") Then
		WinActivate("[CLASS:#32770]", "&Yes")
		Sleep(300)
		ControlClick("[CLASS:#32770]", "&Yes", 'Button2')
		Send('{ESC}')
	EndIf
	
	If WinExists("[CLASS:#32770]", "&Save") Then
		WinActivate("[CLASS:#32770]", "&Save")
		Sleep(300)
		ControlClick("[CLASS:#32770]", "&Save", 'Button1')
		Send('{ESC}')
	EndIf
	
	If WinExists("[CLASS:#32770]", "OK") Then
		WinActivate("[CLASS:#32770]", "OK")
		Sleep(300)
		ControlClick("[CLASS:#32770]", "OK", 'Button2')
		Send('{ESC}')
	EndIf
	
	Local $FileList=_FileListToArray($COMMON_TEST_FOLDER_PATH, '*', 1)
	If @Error Then Return
	For $i = 1 to $FileList[0]
		FileDelete($COMMON_TEST_FOLDER_PATH & $FileList[$i])
	Next
EndFunc

Func FEFunction()
	If $sPMVersion = "SE" Then
		Return 0
	EndIf
EndFunc

Func Common_DeleteFile($sFile, $TestCaseID, $sFunctionName)
	If Not FileDelete($sFile) Then
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'Common_DeleteFile($sFile, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
		Return False
	EndIf	
	Return True	
EndFunc

Func Common_CopyFile($sSrc, $sDes, $TestCaseID, $sFunctionName)
	If Not FileCopy($sSrc, $sDes, 9) Then
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'Common_CopyFile($sSrc, $sDes, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
		Return False
	EndIf	
	Return True
EndFunc

Func Common_ScreenCaprureWindow_Ex($sPerformResultPath,$sCaptureImage,$WndTitle, $sText, $TestCaseID, $sFunctionName)
	If WinExists($WndTitle) And $WndTitle <> "" Then
		Local $iPos = GetWindowPostion($WndTitle)
		If @error Then Return False
			WinActivate($WndTitle)
			Sleep(400)
			_ScreenCapture_CaptureWnd($sPerformResultPath & $sCaptureImage, WinGetHandle($WndTitle, $sText), 3, 3 ,$iPos[2] - 3,$iPos[3] - 3, False)		
			Sleep(1000)
		Return True
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'Common_ScreenCaprureWindow_Ex($sPerformResultPath,$sCaptureImage,$WndTitle, $sText, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False	
EndFunc

Func Common_GetTestStepInSTD($sExcelSheetName,$iCurrentSheetTotalLineNumber,$TestCaseID,$iRescolumn,$sCusMsg)
	If Not _ExcelSheetActivate($oExcel, $sExcelSheetName) Then Return False
	Local $aArray1 = _ExcelReadArray($oExcel, 1, $iTestIDCoulmn, $iCurrentSheetTotalLineNumber, 1)
	If @error Then Return False
	Local $aiResult = _ArrayFindAll($aArray1, $TestCaseID)
	If @error Then Return False
	Local $TestCaseIDLineNumber = $aiResult[0] + 1
	Local $sStep1_ = _ExcelReadArray($oExcel, $TestCaseIDLineNumber, $iFirstStepCoulmn,1,0) 
	If @error Then Return False
	Local $sStep2_ =  _ExcelReadArray($oExcel, $TestCaseIDLineNumber, $iSecondStepCoulmn,1,0) 
	If @error Then Return False
	Local $sStep3_ =  _ExcelReadArray($oExcel, $TestCaseIDLineNumber, $iThirdStepCoulmn,1,0) 
	If @error Then Return False
	Local $sStep4_ =  _ExcelReadArray($oExcel, $TestCaseIDLineNumber, $iFourthStepCoulmn,1,0) 
	If @error Then Return False
	Local $sRes_ =  _ExcelReadArray($oExcel, $TestCaseIDLineNumber, $iRescolumn,1,0) 
	If @error Then Return False
	Local $sStep1 = '1:'   &  $sStep1_[0]
	Local $sStep2 = '2:'   &  $sStep2_[0]
	Local $sStep3 = '3:'   &  $sStep3_[0]
	Local $sStep4 = '4:'   &  $sStep4_[0]
	Local $sRes   = 'Res:' &  $sRes_[0] & @CRLF & $sCusMsg
	Return Common_ExecuteStep_EX1($sStep1, $sStep2, $sStep3, $sStep4, $sRes)
EndFunc
	
Func Common_ScreenCaprureWindow($sPerformResultPath,$sCaptureImage,$WndTitle)
	If WinExists($WndTitle) And $WndTitle <> "" Then
		Local $iPos = GetWindowPostion($WndTitle)
		If @error Then Return False
		_ScreenCapture_CaptureWnd($sPerformResultPath & $sCaptureImage, WinGetHandle($WndTitle), 3, 3 ,$iPos[2] - 3,$iPos[3] - 3, False)		
		Sleep(1000)
	EndIf
EndFunc

Func GetWindowPostion($WndTitle)
	If WinExists($WndTitle) And $WndTitle <> "" Then
		Local $size = WinGetPos($WndTitle)
		If @error Then Return False
		Local $xy[4] = [$size[0], $size[1], $size[2], $size[3]]
		Return $xy
	EndIf	
EndFunc

Func Common_GetAllAutomationTestCaseNumber($sTempTXTPath_)
	Local $CountLines_ = _FileCountLines($sTempTXTPath_)
	Return $CountLines_
EndFunc

Func Common_SwitchToListView($sPMHandle,$TestCaseID, $sFunctionName)
	ControlClick($sPMHandle, '', $sSwicthToListViewButtonCtrInfo)
	If @error Then 
		Return False
	Else
		Return True
	EndIf
EndFunc

Func Common_SwitchToFunctionFolder($sPMHandle, $sFolderName, $TestCaseID, $sFunctionName)
	Local $hTree = ControlGetHandle($sPMHandle, "", $sTreeViewCtrInfo)
	If $hTree = "" Then 
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'Common_SwitchToFunctionFolderInDiskC($sPMHandle, $sFolderName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
		Return False
	EndIf	
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, @UserName)
	If $hItemFound <> 0 Then
		_GUICtrlTreeView_Expand($hTree,$hItemFound,False)
		Sleep(200)
		Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, $sComputer_DiskVolumeName)
		If $hItemFound1 <> 0 Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
			Sleep(200)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, $sDiskC_DiskVolumeName)
			If $hItemFound2 <> 0 Then
				_GUICtrlTreeView_Expand($hTree,$hItemFound2,True)
				Sleep(200)
				Local $hItemFound4 = _GUICtrlTreeView_FindItem($hTree, 'AutomationTest')
					_GUICtrlTreeView_Expand($hTree,$hItemFound4,True)
					Sleep(200)				
					Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sFolderName)
					If $hItemFound3 <> 0 Then
						_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
						Sleep(200)
						_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
						Sleep(200)
						;Click again for the situtaion if the folder can not display in tree view at first time click.
						Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sFolderName)
						_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
						Sleep(200)
						_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
						Sleep(300)
						Return True
					EndIf
			EndIf
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'Common_SwitchToFunctionFolderInDiskC($sPMHandle, $sFolderName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func Common_Get_Treeview_Handle($hPMHandle)
	Return ControlGetHandle($hPMHandle, "",$sTreeViewCtrInfo)
EndFunc

Func Common_SwitchToTestFolder($sPMHandle, $TestCaseID)
	Local $hTree = ControlGetHandle($sPMHandle, "", $sTreeViewCtrInfo)
	If $hTree = "" Then 
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'Common_SwitchToFunctionFolderInDiskC($sPMHandle, $sFolderName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
		Return False
	EndIf	
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, @UserName)
	If $hItemFound <> 0 Then
		_GUICtrlTreeView_Expand($hTree,$hItemFound,False)
		Sleep(200)
		Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, $sComputer_DiskVolumeName)
		If $hItemFound1 <> 0 Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
			Sleep(200)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, $sDiskC_DiskVolumeName)
			If $hItemFound2 <> 0 Then
				_GUICtrlTreeView_Expand($hTree,$hItemFound2,True)
				Sleep(200)
				Local $hItemFound4 = _GUICtrlTreeView_FindItem($hTree, 'AutomationTest')
					_GUICtrlTreeView_Expand($hTree,$hItemFound4,True)
					Sleep(200)				
					Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, '0TestFolder')
					If $hItemFound3 <> 0 Then
						_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
						Sleep(200)
						_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
						Sleep(200)
						;Click again for the situtaion if the folder can not display in tree view at first time click.
						Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, '0TestFolder')
						_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
						Sleep(200)
						_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
						Sleep(300)
						Return True
					EndIf
			EndIf
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Common_WriteLog($sFaile & 'Common_SwitchToFunctionFolderInDiskC($sPMHandle, $sFolderName, $TestCaseID, $sFunctionName)', $TestCaseID, $sFunctionName, ' ')
	Return False
EndFunc

Func Common_SwitchToFolderInRootDiskC_($sPMHandle, $sFolderName)
	Local $hTree = ControlGetHandle($sPMHandle, "", $sTreeViewCtrInfo)
	If $hTree = "" Then 
		Common_ClosePMWhenException()
		Return False
	EndIf	
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, @UserName)
	If $hItemFound <> 0 Then
		_GUICtrlTreeView_Expand($hTree,$hItemFound,False)
		Sleep(500)
		Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, $sComputer_DiskVolumeName)
		If $hItemFound1 <> 0 Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
			Sleep(500)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, $sDiskC_DiskVolumeName)
			If $hItemFound2 <> 0 Then
				_GUICtrlTreeView_Expand($hTree,$hItemFound2,True)
				Sleep(500)
				Local $hItemFound4 = _GUICtrlTreeView_FindItem($hTree, 'AutomationTest')
					_GUICtrlTreeView_Expand($hTree,$hItemFound4,True)
					Sleep(500)				
					Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sFolderName)
					If $hItemFound3 <> 0 Then
						_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
						Sleep(300)
						_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
						Sleep(300)
						;Click again for the situtaion if the folder can not display in tree view at first time click.
						Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sFolderName)
						_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
						Sleep(300)
						_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
						Sleep(300)
						Return True
					EndIf
			EndIf
		EndIf
	EndIf
	Common_ClosePMWhenException()
	Return False
EndFunc


Func Common_SwitchToFolderInRootDiskC($sPMHandle, $sFolderName)
	Local $hTree = ControlGetHandle($sPMHandle, "", $sTreeViewCtrInfo)
	If $hTree == "" Then $hTree = ControlGetHandle($sPMHandle, "", 'SysTreeView321')
	If $hTree == "" Then
		Common_ClosePMWhenException()
		Return False
	EndIf	
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, @UserName)
	If $hItemFound <> 0 Then
		_GUICtrlTreeView_Expand($hTree,$hItemFound,False)
		Sleep(500)
		Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, $sComputer_DiskVolumeName)
		If $hItemFound1 <> 0 Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
			Sleep(500)
			Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, $sDiskC_DiskVolumeName)
			If $hItemFound2 <> 0 Then
				_GUICtrlTreeView_Expand($hTree,$hItemFound2,True)
				Sleep(500)
				Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sFolderName)
				If $hItemFound3 <> 0 Then
					_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
					Sleep(300)
					_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
					Sleep(300)
					;Click again for the situtaion if the folder can not display in tree view at first time click.
					Local $hItemFound3 = _GUICtrlTreeView_FindItem($hTree, $sFolderName)
					_GUICtrlTreeView_ClickItem($hTree, $hItemFound3)
					Sleep(300)
					_GUICtrlTreeView_Expand($hTree,$hItemFound3,True)
					Sleep(300)
					Return 1
				EndIf
			EndIf
		EndIf
	EndIf
	Return @error
EndFunc

Func Common_SwitchToFEOrSESampleFolder($sPMHandle, $sPMVersion,$iSleepTime,$hPMHandle)
	Local $hTree = ControlGetHandle($sPMHandle, "", $sTreeViewCtrInfo)
	If $hTree <> "" Then
		$sPMVersion = StringUpper($sPMVersion)
		If $sPMVersion = "FE" Then
			Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, "FE Sample")
			If $hItemFound1 <> 0 Then
				If _GUICtrlTreeView_ClickItem($hTree, $hItemFound1) Then
					_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
					Common_SleepTime($iSleepTime)	
					If WinActivate($hPMHandle) Then
						Return 1
					Else
						Return @error
					EndIf
				Else
					Return @error
				EndIf
			EndIf
		EndIf		
		If $sPMVersion = "SE" Then
			Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, "SE Sample")
			If $hItemFound1 <> 0 Then
				If _GUICtrlTreeView_ClickItem($hTree, $hItemFound1) Then
					_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
					Common_SleepTime($iSleepTime)	
					If WinActivate($hPMHandle) Then
						Return 1
					Else
						Return @error
					EndIf
				Else
					Return @error
				EndIf
			EndIf
		EndIf	
	EndIf
	Return @error
EndFunc


Func Common_STDInfro($oExcel,$TestCase_Number,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn,$CurrentSheetTotalLineNumber)
	Local $iExcelLineNumber = Common_CurrentTestCaseLineNumber($oExcel,$TestCase_Number,$sExcelSheetName,$CurrentSheetTotalLineNumber)
	Local $_sTestPurpose = ReadExcelContent($oExcel,$sTestPurpose,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	Local $sTestStep1 = ReadExcelContent($oExcel,$sFirstClass,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	Local $sTestStep2 = ReadExcelContent($oExcel,$sSecondClass,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	Local $sTestStep3 = ReadExcelContent($oExcel,$sThirdClass,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	Local $sTestStep4 = ReadExcelContent($oExcel,$sFourClass,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	Local $sTestStep5 = ReadExcelContent($oExcel,$sFiveClass,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	Local $_sExpectedResult = ReadExcelContent($oExcel,$sExpectedResult,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)	
	Local $InitialResult[8]
	$InitialResult[0] = $iExcelLineNumber
	$InitialResult[1] = $_sTestPurpose
	$InitialResult[2] = $sTestStep1
	$InitialResult[3] = $sTestStep2
	$InitialResult[4] = $sTestStep3
	$InitialResult[5] = $sTestStep4
	$InitialResult[6] = $sTestStep5
	$InitialResult[7] = $_sExpectedResult
	Return $InitialResult
EndFunc	


Func ReadExcelContent($oExcel,$sContent,$iExcelLineNumber,$sExcelSheetName,$iFifthStepCoulmn,$iExpectedResultCoulmn)
	_ExcelSheetActivate($oExcel, $sExcelSheetName)	
	Switch $sContent
	Case 'Test Purpose'	
		Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iTestPurposeCoulmn,1,0) 
	Case 'First Class'
		Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iFirstStepCoulmn,1,0) 		
	Case 'Second Class'
		Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iSecondStepCoulmn,1,0) 	
	Case 'Third Class'
		Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iThirdStepCoulmn,1,0) 		
	Case 'Four Class'
		Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iFourthStepCoulmn,1,0) 			
	Case 'Five Class'
		If $iFifthStepCoulmn = "" Then
			Local $aArray1[1]
			$aArray1[0] = ""
		Else
			Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iFifthStepCoulmn,1,0) 
		EndIf		
	Case 'Expected Result'
		Local $aArray1 = _ExcelReadArray($oExcel, $iExcelLineNumber, $iExpectedResultCoulmn,1,0) 	
	EndSwitch
		Return $aArray1[0]
EndFunc

Func Common_IsExecuteTheTestCase($sExecuteTestCaseLevel,$sTestCaseLevel)   ;modify
	$sExecuteTestCaseLevel = StringUpper($sExecuteTestCaseLevel)
	$sTestCaseLevel = StringUpper($sTestCaseLevel)
	If $sExecuteTestCaseLevel = "ALL" Then
		Return True
	ElseIf  $sExecuteTestCaseLevel == $sTestCaseLevel Then
		Return True
	Else
		Return False
	EndIf
EndFunc

Func Common_WriteAllTestCaseIDtoTXT($oExcel,$iCurrentSheetTotalLineNumber,$sTempTXTPath_)
	Local $file = FileOpen($sTempTXTPath_, 129)
	Local $iID,$i26,$slevel
	If $file = -1 Then
		Return @error
	EndIf
	For $i = 56 to $iCurrentSheetTotalLineNumber
		$i26 = _ExcelReadCell($oExcel, $i,26)
		If $i26 = 1 Then
			$iID = _ExcelReadCell($oExcel, $i,6)
			If Not @error Then
				If $sExecuteTestCaseLevel = "ALL" Then   
					FileWrite($file, $iID & @CRLF)
					Else
						Local $bIsExecuteTheTestCase = Common_IsExecuteTheTestCase(_ExcelReadCell($oExcel, $i,4),$sExecuteTestCaseLevel)    ;Judge current test case level is equal the key ExecuteTestCaseLevel in ini.
						If $bIsExecuteTheTestCase = True Then   ;equal
							FileWrite($file, $iID & @CRLF)
						EndIf
				EndIf
			EndIf
		EndIf
	Next
	FileClose($file)
EndFunc

	
Func Common_GetTestCaseLevel($oExcel, $TestCase_Number,$sExcelSheetName,$CurrentSheetTotalLineNumber)   ;modify
	Local $iExcelLineNumber = Common_CurrentTestCaseLineNumber($oExcel,$TestCase_Number,$sExcelSheetName,$CurrentSheetTotalLineNumber)
	If $iExcelLineNumber == False Then Return False
	Local $sLevel
	Local $iLevelColumn = 4
	$sLevel = _ExcelReadArray($oExcel, $iExcelLineNumber ,$iLevelColumn, 1,0) 
	If @error Then Return False
	Return  StringUpper($sLevel[0])
EndFunc

Func Common_CurrentTestCaseLineNumber($oExcel,$TestCase_Number,$sExcelSheetName,$CurrentSheetTotalLineNumber) 
	_ExcelSheetActivate($oExcel, $sExcelSheetName)
	If @error Then Return False
	Local $aArray1 = _ExcelReadArray($oExcel, 1, $iTestIDCoulmn, $CurrentSheetTotalLineNumber, 1) ;Row = 1, Column = 6 = Test ID
	If @error Then Return False
	Local $aiResult = _ArrayFindAll($aArray1, $TestCase_Number)
	If @error Then
		Return False
	Else
		Return $aiResult[0] + 1
	EndIf
EndFunc

Func Common_AutomationTestCaseNumber($iNumber)
	$iNumber += 1
	Return $iNumber
EndFunc


Func Common_GetNumberInExcelSheet($oExcel,$sExcelSheetName)   ;modify
	Local $iNumber[5],$a
	Local $iLineNumber = 56   ;Start line number.
	Local $iTestCaseNumber = 0 
	Local $iHTestCaseNumber = 0 
	Local $iMTestCaseNumber = 0 
	Local $iLTestCaseNumber = 0 
	_ExcelSheetActivate($oExcel, $sExcelSheetName)
	If @error Then Return False
	While True
		Local $sCellValue = _ExcelReadCell($oExcel, $iLineNumber, 6)
		If @error Then Return False
		$a = StringInStr ($sCellValue , ".")
		If @error Then Return False
		Local $var = StringLeft ($sCellValue, $a - 1)
		Local $var1 = Number($var)
		If $var1 <> 0 Then
			Local $sLevel = _ExcelReadCell($oExcel, $iLineNumber, 4)
			If @error Then Return False
			$sLevel = StringUpper($sLevel)
			If $sLevel = "H" Then
				$iHTestCaseNumber += 1
			EndIf
			If $sLevel = "M" Then
				$iMTestCaseNumber += 1
			EndIf
			If $sLevel = "L" Then
				$iLTestCaseNumber += 1
			EndIf			
			$iTestCaseNumber += 1
		EndIf
		If $sCellValue = "" Then
			ExitLoop
		EndIf
		$iLineNumber += 1
	WEnd
	$iNumber[0] = $iLineNumber - 1
	$iNumber[1] = $iTestCaseNumber
	$iNumber[2] = $iHTestCaseNumber 
	$iNumber[3] = $iMTestCaseNumber 
	$iNumber[4] = $iLTestCaseNumber
	Return $iNumber
EndFunc


Func Common_FiveStepAndExpectResultColumnNumber($oExcel,$sExcelSheetName)
	Dim $sRes[2]
	Dim $aiResult4,$aiResult5,$aiResult6,$aiResult7,$sResult1,$sResult2,$sResult3,$sResult4
	_ExcelSheetActivate($oExcel, $sExcelSheetName)
	Local $aArray1 = _ExcelReadArray($oExcel, 1, 6, 100, 1) 
	Local $aiResult = _ArrayFindAll($aArray1, 'Test ID',0 ,0 ,1)   ;Test ID row number
	If $aiResult = -1 Then
		Local $aiResult = _ArrayFindAll($aArray1, 'Test Case ID',0 ,0 ,1)   ;Test ID row number
	EndIf
	Local $aArray2 = _ExcelReadArray($oExcel, $aiResult[0]+2, 6, 30, 0)   ;Step row number
	$sResult1 = _ArrayFindAll($aArray2, 'five class',0 ,0 ,0)
	$sResult2 = _ArrayFindAll($aArray2, 'five step',0 ,0 ,0)
	$sResult3 = _ArrayFindAll($aArray2, 'fifth class',0 ,0 ,0)
	$sResult4 = _ArrayFindAll($aArray2, 'fifth step',0 ,0 ,0)
	If $sResult1 = -1 And $sResult2 = -1 And $sResult3 = -1 And $sResult4 = -1 Then   ;Not has five step.   
		$sRes[0] = ''
	Else
		$sRes[0] = 12   ;five step column number.
	EndIf
	Local $aiResult3 = _ArrayFindAll($aArray2, $sExpectedResult,0 ,0 ,0)
	$aiResult4 = _ArrayFindAll($aArray2, 'four class',0 ,0 ,0)
	If $aiResult4 = -1 Then
	Else
		$sRes[1] = 11 + ($aiResult3[0] - $aiResult4[0])
	EndIf	
	$aiResult5 = _ArrayFindAll($aArray2, 'four step',0 ,0 ,0)
	If $aiResult5 = -1 Then
	Else
		$sRes[1] = 11 + ($aiResult3[0] - $aiResult5[0])
	EndIf		
	$aiResult6 = _ArrayFindAll($aArray2, 'fourth class',0 ,0 ,0)
	If $aiResult6 = -1 Then
	Else
		$sRes[1] = 11 + ($aiResult3[0] - $aiResult6[0])
	EndIf	
	$aiResult7 = _ArrayFindAll($aArray2, 'fourth step',0 ,0 ,0)
	If $aiResult7 = -1 Then
	Else
		$sRes[1] = 11 + ($aiResult3[0] - $aiResult7[0])
	EndIf
	Return $sRes
EndFunc

Func GetExcelObject() 
Dim $sRes[2]	
	Local $FileList=_FileListToArray($sRootFolder, '*.xls', 1), $Path
	If @Error Then
		MsgBox (0,"","No excle Found.")
		Exit
	EndIf
	
	For $i =1 to $FileList[0]
		If StringInStr ($FileList[$i], "-")  <> 0 Then
			$Path = $sRootFolder & $FileList[$i]
			Local $oExcel = _ExcelBookOpen($Path, 0, True) 
			Local $aArray = _ExcelSheetList($oExcel)
			For $i = 1 to $aArray[0]
				If $aArray[$i] =  'Smoking Test' Then
					$sRes[0] = $Path
					$sRes[1] = $oExcel
					Return $sRes
				EndIf	
			Next
		EndIf
	Next
	MsgBox (0,"","No execle Found.")
	Exit
EndFunc



Func GetSettingIniPath()   ;Get PCode.ini path.
	Local $FileList=_FileListToArray($sRootFolder, '*.ini', 1), $Path
	If @Error Then
		MsgBox (0,"","No PCode.ini  Found.")
		Exit
	EndIf
	For $i =1 to $FileList[0]
		If StringInStr ($FileList[$i], "-")  <> 0 Then
			If @Error Then
				MsgBox (0,"","No PCode.ini  Found.")
				Exit
			EndIf
			$Path = $sRootFolder & $FileList[$i]
			If IniRead($Path, 'BasicInfo', 'SleepTime', "NotFound") <> 'NotFound' And  IniRead($Path, 'BasicInfo', 'SleepTime', "NotFound") <> '' Then
				Return $Path
			EndIf
		EndIf
	Next
	MsgBox (0,"","No PCode.ini Found.")
	Exit
EndFunc

Func Common_WriteLog_Fail($sCaptureImage,$TestPurpose, $Step1 ,$Step2,$Step3,$Step4,$Step5,$ExpectedResult, $TestCase_Number,$sFileName,$sStepAndCheckPoint,$iFlag = -1)
	Dim $Log_Path = @DesktopDir & "\"
	Local $sDateNow, $sTimeNow, $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1 
	$TestCase_Number = $TestCase_Number 
	If $sCaptureImage = "" Then
		If $Step4 <> '' And $Step3 <> '' And $Step2 <> '' And $Step5 <> '' Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & '      3.' & $Step3 & @CRLF & '      4.' & $Step4 & @CRLF & '      5.' & $Step5 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf
		If $Step4 <> '' And $Step3 <> '' And $Step2 <> '' Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & '      3.' & $Step3 & @CRLF & '      4.' & $Step4 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint 
		EndIf
		If $Step3 <> '' And $Step2 <> '' And $Step4 = "" Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & '      3.' & $Step3 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf	
		If $Step2 <> '' And $Step1 <> '' And $Step4 = "" And $Step3 = "" Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf	
		If $Step1 <> '' And $Step2 = '' And $Step4 = "" And $Step3 = "" Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf
	Else
		If $Step4 <> '' And $Step3 <> '' And $Step2 <> '' And $Step5 <> '' Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & '      3.' & $Step3 & @CRLF & '      4.' & $Step4 & @CRLF & '      5.' & $Step5 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf
		If $Step4 <> '' And $Step3 <> '' And $Step2 <> '' Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & '      3.' & $Step3 & @CRLF & '      4.' & $Step4 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf
		If $Step3 <> '' And $Step2 <> '' And $Step4 = "" Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & '      3.' & $Step3 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf	
		If $Step2 <> '' And $Step1 <> '' And $Step4 = "" And $Step3 = "" Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & '      2.' & $Step2 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf	
		If $Step1 <> '' And $Step2 = '' And $Step4 = "" And $Step3 = "" Then
			$sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & "____FAIL" & @CRLF & "Test Purpose: " & $TestPurpose & @CRLF & "Step: 1." & $Step1 & @CRLF & "ExpectedResult: " & $ExpectedResult & @CRLF & "Automation test Step and check point: " & $sStepAndCheckPoint
		EndIf			
	EndIf
	If $iFlag <> -1 Then
		$sMsg &= @CRLF & FileRead ($Log_Path&$sFileName)
		$iOpenMode = 2
	EndIf
	$hOpenFile = FileOpen ($Log_Path&$sFileName, 129)
	If $hOpenFile = -1 Then Return SetError(1, 0, 0)
	$iWriteFile = FileWriteLine ($hOpenFile, $sMsg)
	If $iWriteFile = -1 Then Return SetError (2, 0, 0)
	Return FileClose ($hOpenFile)
EndFunc

Func Common_OutputFunctionName($sFunctionName)
	Return "AutoIT script occurred an error in function ( " & $sFunctionName & " ).Plese execuete this test case by manual."
EndFunc


Func Common_WriteLog ($sLogMsg, $TestCase_Number,$sFunctionName,$bReproduce,$iFlag = -1)
	Dim $Log_Path = @DesktopDir & "\"
	$TestCase_Number = $TestCase_Number 
	Local $sFileName = $sFunctionName&".Log"
	Local $sDateNow, $sTimeNow, $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1 
    $sMsg = @CRLF & "Test Case " & $TestCase_Number & ":" & $sLogMsg 
	If $iFlag <> -1 Then
		$sMsg &= @CRLF & FileRead ($Log_Path&$sFileName)
		$iOpenMode = 2
	EndIf
	$hOpenFile = FileOpen ($Log_Path&$sFileName, 129)
	If $hOpenFile = -1 Then Return SetError(1, 0, 0)
	$iWriteFile = FileWriteLine ($hOpenFile, $sMsg)
	If $iWriteFile = -1 Then Return SetError (2, 0, 0)
	
	;Write the Reproduce Result Ini
	If $bReproduce = True  Then
		WriteReproduceResultIni($sFunctionName,$TestCase_Number,$sLogMsg)
	EndIf		
		
		
	Return FileClose ($hOpenFile)
EndFunc 

Func Common_WriteTestCaseInfoToLog($sExcelSheetName,$iNumber,$sFileName,$TotalTestCaseNumber)
	Local $iOpenMode,$hOpenFile,$iWriteFile
	Dim $Log_Path = @DesktopDir & "\"
	Dim $sMsg = @CRLF & $TotalTestCaseNumber & $sExcelSheetName & ":" & $iNumber 
	$sMsg &= @CRLF & FileRead ($Log_Path&$sFileName)
	$hOpenFile = FileOpen ($Log_Path&$sFileName, 130)
	$iWriteFile = FileWriteLine ($hOpenFile, $sMsg)
	If $iWriteFile = -1 Then Return SetError (2, 0, 0)
	FileClose ($hOpenFile)
	Return True
EndFunc

Func Common_CompareImage ($file1,$file2,$Pixels=5)
		Local $dllb,$dllc,$dlla,$dll,$result
		$dllb = DllOpen ($Dll3)
		$dllc = DllOpen ($Dll4)
		$dlla = DllOpen ($Dll1)
		$dll = DllOpen ($Dll2)
		$result = DllCall($dll, "int","Auto_CompareFile", "str",$file1, "str",$file2,"int",$Pixels)
		If Not @error Then
			If $result[0] = 1 Then 
				Return 1
			Else
				Return @error
			EndIf
		EndIf
		DllClose($dll)
		DllClose($dlla)
		DllClose($dllb)
		DllClose($dllc)
EndFunc

Func Common_CompareFile ($file1,$file2)
	If FileExists($file1) And FileExists($file2) And (FileGetSize ($file1) > 1) And (FileGetSize ($file2) > 1) Then
		#cs
		Local $file_A,$chars_A,$file_B,$chars_B
		$file_A = FileOpen ($file1, 16)
		$chars_A = FileRead ($file_A)
		$file_B = FileOpen ($file2, 16)
		$chars_B = FileRead ($file_B)
		FileClose ($file_A)
		FileClose ($file_B)
		If FileExists($file1) Then
			If $chars_A = $chars_B Then
				Return 1
			Else
				Return @error
			EndIf
		Else
			Return @error
		EndIf
		#ce
		Local $var = StringRight ($file1, 4)
		;If $var = ".tif" Or $var = ".png" Then
		If $var = ".tif" Or $var = ".png" Then
			Return Common_CompareImage ($file1,$file2)
		Else	
			Local $file_A,$chars_A,$file_B,$chars_B
			$file_A = FileOpen ($file1, 16)
			$chars_A = FileRead ($file_A)
			$file_B = FileOpen ($file2, 16)
			$chars_B = FileRead ($file_B)
			FileClose ($file_A)
			FileClose ($file_B)
			If FileExists($file1) Then
				If $chars_A = $chars_B Then
					Return 1
				Else
					Return @error
				EndIf
			Else
				Return @error
			EndIf
		EndIf	
	EndIf
EndFunc

Func Common_Del_DB()
	If $iDelDB = 1 Then
		Local $FileList
		$FileList = _FileListToArray($PMFolder, "*", 2)	
		If @error Then
		Else
			For $i = 1 To $FileList[0]
				If @error Then
				Else
					DirRemove($PMFolder & $FileList[$i], 1)
				EndIf
			Next
		EndIf
		FileDelete($PMFolder & "*.*")
		If ProcessExists("Prestopm.exe") Then
			ProcessClose("Prestopm.exe")
		EndIf	
		If ProcessExists("Pmsb.exe") Then
			ProcessClose("Pmsb.exe")
		EndIf
		If ProcessExists("PMSpeed.exe") Then
			ProcessClose("PMSpeed.exe")
		EndIf
		If ProcessExists("PageViewer.exe") Then
			ProcessClose("PageViewer.exe")
		EndIf
		DirRemove(Get_DB_Path (), 1)
		Run(PMSpeedEXE_Path())
		If @error Then Return False
		Common_SleepTime(1)
	EndIf
EndFunc

Func Get_DB_Path ()   ;Get PM DB folder path in local setting.
	Local $DBPath = @UserProfileDir & '\AppData\Local\NewSoft\'
	Return $DBPath
	#cs
	Dim $FoderList,$FoderList1,$FoderList2,$s
	$FoderList = _FileListToArray (@UserProfileDir)
	If @error Then Return False
	For $i = 1 To $FoderList[0]
		$FoderList1 = _FileListToArray (@UserProfileDir & "/" & $FoderList[$i])
		If @error Then Return False
		If @error Then
		Else
			For $x = 1 To $FoderList1[0]
				If @error Then
				Else
					$FoderList2 = _FileListToArray (@UserProfileDir & "/" & $FoderList[$i] & "/" & $FoderList1[$x])
					If @error Then Return False
					If @error Then
					Else
						For $y = 1 To $FoderList2[0]
							If $FoderList2[$y] = "NewSoft" Then
								 $s = @UserProfileDir & "/" & $FoderList[$i] & "/" & $FoderList1[$x] & "/" & $FoderList2[$y]
								Return $s
								ExitLoop
							EndIf
						Next
						ExitLoop
					EndIf
				EndIf
			ExitLoop
			Next
		EndIf
	Next
	Return @error
	#ce
EndFunc

Func PrestopmEXE_Path ()
	Dim $FileList,$FileList1,$Path
	$FileList = _FileListToArray (@ProgramFilesDir, "*", 2)
	If Not @error Then
		$FileList = _FileListToArray (@ProgramFilesDir & "\NewSoft", "*", 2)
		If Not @error Then
			For $i =1 to $FileList[0]
				$FileList1 = _FileListToArray (@ProgramFilesDir & "\NewSoft" & "\" & $FileList[$i], "Prestopm.exe", 1)
				If Not @error Then
					If $i = $FileList[0] Then
						If @error Then 
							Return @error	
						Else		
							$Path = @ProgramFilesDir & "\NewSoft\" & $FileList[$i] & "\" & $FileList1[$i]
							Return $Path
						EndIf
					EndIf	
				EndIf	
			Next
		EndIf	
	EndIf
	Return @error
EndFunc

Func PMSpeedEXE_Path()
	Dim $FileList,$FileList1,$Path
	$FileList = _FileListToArray ("C:\Program Files\NewSoft", "*", 2)
	If @error Then
		$FileList = _FileListToArray ("C:\Program Files (x86)\NewSoft", "*", 2)
			For $i =1 to $FileList[0]
				$FileList1 = _FileListToArray ("C:\Program Files (x86)\NewSoft" & "\" & $FileList[$i], "PMSpeed.exe", 1)
				If $i = $FileList[0] Then
					If @error Then 
						MsgBox("", "", "PMSpeed.exe has not found!")	
					Else		
						$Path = "C:\Program Files (x86)\NewSoft\" & $FileList[$i] & "\" & $FileList1[$i]
						Return $Path
					EndIf
				EndIf	
			Next
	Else	
			For $i =1 to $FileList[0]
				$FileList1 = _FileListToArray ("C:\Program Files\NewSoft" & "\" & $FileList[$i], "PMSpeed.exe", 1)
				If $i = $FileList[0] Then
					If @error Then 
						MsgBox("", "", "PMSpeed.exe has not found!")
					Else
						$Path = "C:\Program Files\NewSoft\" & $FileList[$i] & "\" & $FileList1[$i]
						Return $Path
					EndIf
				EndIf
			Next
	EndIf
EndFunc

Func Common_SleepTime($Num=1)
	Local $Timer
	Local $var = ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'SleepTime' )   
	If @error Then 
		MsgBox("", "", "Error occurred, probably no SleepTime key in PCode.ini or TestCaseStepAndCheckPoint.ini")
		Return False
		Exit
	Else
		$Timer= $var*$Num
	EndIf
	sleep($Timer)	
EndFunc

Func ReadIniKeyValue($path, $section, $key)     ;Get the specify key vaule from ini.
	Local $var = IniRead($path, $section, $key, "NotFound")
	If @error Then
		MsgBox("", "ReadINI", 'Error occurred, probably no PCode.ini or TestCaseStepAndCheckPoint.ini')
		Return False
		Exit
	Else
		If $var = "NotFound" Then
			MsgBox("", "ReadINI", 'Error occurred, probably no sunch key (' & $key & ') value in PCode.ini or TestCaseStepAndCheckPoint.ini')
			Return False
			Exit
		Else
			Return $var
		EndIf
	EndIf
EndFunc   

Func PMVerSion()
	Local $var = ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'PMVersion')   
	If @error Then 
		MsgBox("", "", "Error occurred, probably no PMVerSion.ini or TestCaseStepAndCheckPoint.ini")
		Exit
	Else
		Return $var
	EndIf
EndFunc

Func Common_SleepInSeconds($i)
	Sleep($i * 1000)
EndFunc


Func Common_Run_PageManager_Ex($TestCaseID, $sFunctionName)
	Local $Titile,$size
	Local $avArray[100]
	FileDelete(@MyDocumentsDir & "\My PageManager\*.*")
	Sleep(500)
	DirRemove(@MyDocumentsDir & "\My PageManager\", 1)
	Sleep(500)
	DirCreate(@MyDocumentsDir & "\My PageManager\")
	Sleep(1000)
	Local $PIDa = Run(PrestopmEXE_Path(), "", @SW_MAXIMIZE)
	If @error Then
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'Common_Run_PageManager_Ex()' , $TestCaseID, $sFunctionName, ' ')
	EndIf
	Common_SleepTime(5)
	If ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'License')  Then
		WinActivate("License")
		ControlClick("License", "", 1)
		Common_SleepTime(6)
	EndIf
	If WinExists("[CLASS:#32770]", "Try") Then
		WinActivate("[CLASS:#32770]", "Try")
		ControlClick("[CLASS:#32770]", "Try", 1000)
		Common_SleepTime(20)
	EndIf
	If WinExists("Scan Central") Then
		WinActivate("Scan Central")
		Sleep(500)
		WinClose("Scan Central")
	EndIf
	If ProcessExists ("PageViewer.exe") Then
		ProcessClose ( "PageViewer.exe")
		Sleep (500)
	EndIf
	Local $Var = WinList()
	For $i = 1 to $Var[0][0]
		If $Var[$i][0] <> "" And IsVisible($var[$i][1]) Then
			If Not @error Then
				$avArray[$i] = WinGetProcess($Var[$i][0])   ; Get all visible title PID.
				If Not @error Then
					If $PIDa = $avArray[$i] Then
						$Titile = $Var[$i][0]   ; Get PM title.
						$size = WinGetPos($Titile)   ;Get PM postion and size.
						MouseClick('left',($size[0] + $size[2] / 2), ($size[1])) 
						Common_SleepTime(1)
						Local $h = WinGetHandle($Titile)
						If $h = '' Then 
							Common_ClosePMWhenException()
							Common_WriteLog($sFaile & 'Common_Run_PageManager_Ex()' , $TestCaseID, $sFunctionName, ' ')
							Return $h
						Else
							Return $h
						EndIf
					EndIf
				EndIf
			EndIf
		EndIf
	Next
EndFunc

Func Common_Run_PageManager()
	Local $Titile,$size
	Local $avArray[100]
	Local $PIDa = Run(PrestopmEXE_Path(), "", @SW_MAXIMIZE)
	Local $LicenseWindow = ReadIniKeyValue($sPCodeIniPath, $sSectionBasicInfo, 'License')
	Common_SleepTime(6)
	If $LicenseWindow  Then
		WinActivate("License")
		ControlClick("License", "", 1)
		Common_SleepTime(6)
	EndIf
	If WinExists("[CLASS:#32770]", "Try") Then
		WinActivate("[CLASS:#32770]", "Try")
		ControlClick("[CLASS:#32770]", "Try", 1000)
		Common_SleepTime(20)
	EndIf
	If WinExists("Scan Central") Then
		WinActivate("Scan Central")
		Sleep(500)
		WinClose("Scan Central")
	EndIf
	If ProcessExists ("PageViewer.exe") Then
		ProcessClose ( "PageViewer.exe")
		Sleep (500)
	EndIf
	Local $Var = WinList()
	For $i = 1 to $Var[0][0]
		If $Var[$i][0] <> "" And IsVisible($var[$i][1]) Then
			$avArray[$i] = WinGetProcess($Var[$i][0])   ; Get all visible title PID.
			If Not @error Then
				If $PIDa = $avArray[$i] Then
					$Titile = $Var[$i][0]   ; Get PM title.
					$size = WinGetPos($Titile)   ;Get PM postion and size.
					MouseClick('left',($size[0] + $size[2] / 2), ($size[1])) 
					Common_SleepTime(1)
					Local $h = WinGetHandle($Titile)
					Return $h
				EndIf
			EndIf
		EndIf
	Next
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
		Return 1
  Else
		Return @error
  EndIf
EndFunc

Func Common_ClosePMWhenException()
	If ProcessExists ("PageViewer.exe") Then
		WinActivate($sPageViwerWindowClass)
		Send ("!f")
		Sleep (500)
		Send ("E")   ; Close pageview.
		Sleep (500)
		If ProcessExists ("PageViewer.exe") Then
			ProcessClose ( "PageViewer.exe")
			Sleep (500)
		EndIf
	EndIf	
	
	WinKill ( "[CLASS:Photo_Lightweight_Viewer]" )

	If ProcessExists ("Prestopm.exe") Then
		ProcessClose ( "Prestopm.exe")
	EndIf	

	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd

	RefreshShellTrayToolbar() 
	
	DeleteDesktopFiles()
EndFunc


Func Common_Close_PM ($hHandle)
	For $i=0 To 5
		Send('{ESC}')
		Sleep (100)
	Next
	
	WinKill ( "[CLASS:Photo_Lightweight_Viewer]" )
	
	If ProcessExists ("PageViewer.exe") Then
		WinActivate($sPageViwerWindowClass)
		Send ("!f")
		Sleep (500)
		Send ("E")   ; Close pageview.
		Sleep (500)
		If ProcessExists ("PageViewer.exe") Then
			ProcessClose ( "PageViewer.exe")
			Sleep (500)
		EndIf
	EndIf	
	
	If ProcessExists ("Prestopm.exe") Then
		WinActivate($hHandle)   ;Activate the PM window.
		Sleep(500)
		Send ("!f")
		Sleep (500)
		Send ("E")   ; Close PM.
		Sleep (1000)
		If ProcessExists ("Prestopm.exe") Then
			ProcessClose ( "Prestopm.exe")
			Sleep (1000)
		EndIf
	EndIf	
	
	If ProcessExists('Pmsb.exe') Then
		ProcessClose('Pmsb.exe')
	EndIf
	
	While ProcessExists('POWERPNT.EXE')
		ProcessClose('POWERPNT.EXE')
	WEnd
	
	While ProcessExists('WINWORD.EXE')
		ProcessClose('WINWORD.EXE')
	WEnd
	
	While ProcessExists('OUTLOOK.EXE')
		ProcessClose('OUTLOOK.EXE')
	WEnd
	
	While ProcessExists('iexplore.exe')
		ProcessClose('iexplore.exe')
	WEnd
	
	DeleteDesktopFiles()

	RefreshShellTrayToolbar()
EndFunc

Func _ControlGetPos($Title, $text, $Ctrlid)
	Local $hwnd = WinGetHandle($Title, $text)
	Local $tpoint = DllStructCreate("int X;int Y")
	Local $ControlPos = ControlGetPos($Title, $text, $Ctrlid)
	DllStructSetData($tpoint, "X", $ControlPos[0])
	DllStructSetData($tpoint, "Y", $ControlPos[1])
	Sleep(1000)
	_WinAPI_ClientToScreen($hwnd, $tpoint)
	Local $xy[4] = [DllStructGetData($tPoint, 'X'), DllStructGetData($tPoint, 'Y'), $ControlPos[2], $ControlPos[3]]
	Return $xy
EndFunc  

#cs
Func writeLogFile($correctResultPath, $captureResultPath, $testCaseNumber, $sFileName)
	
	; Compare the check point and output the result.
	If FileExists($correctResultPath) Then   ; Judge the correct result exist or not.
		If FileExists($captureResultPath) Then   ; Judge the captured result exist or not.
			Local $returnOfCompareFile = Common_CompareFile($correctResultPath, $captureResultPath)   ; Compare the capture result and correct result. 
				
			; Write the log file.(Test Case result.)
			If $returnOfCompareFile Then
				Common_WriteLog("PASS", $testCaseNumber,$sFileName)
			Else
				Common_WriteLog("____FAIL,Please compare the capture.", $testCaseNumber,$sFileName)
			EndIf
				
		Else
			Common_WriteLog("____FAIL,The perform result didn't exist.", $testCaseNumber,$sFileName)
		EndIf	
	Else
		Common_WriteLog("____FAIL,The correct result does not exist.", $testCaseNumber,$sFileName)
	EndIf	
EndFunc   ; ==> writeLogFile
#ce

Func clickFolderOnTreeview($PMTitle, $Folder, $Button = "left")
	;Local $TreeViewHandle = ControlGetHandle($PMTitle, "", "SysTreeView321")
	Local $TreeViewHandle = ControlGetHandle($PMTitle, "", 1000)
	Local $Item = _GUICtrlTreeView_FindItem($TreeViewHandle, $Folder)
	_GUICtrlTreeView_ClickItem($TreeViewHandle, $Item, $Button)
EndFunc

Func Common_ReadFile($sPath,$sLine)
	Local $file = FileOpen($sPath, 0)
	; Check if file opened for reading OK
	If $file = -1 Then
		MsgBox(0, "Error", "Unable to open file." & $sPath)
		Exit
	EndIf
	Local $sString = FileReadLine($sPath,$sLine)
	FileClose($file)
	Return $sString
EndFunc

Func CloseOpenedExcel($oExcel)
	_ExcelBookClose($oExcel,0)
	Sleep(2000)
	For $i = 1 to 30
		If ProcessExists('EXCEL.EXE') Then
			ProcessClose('EXCEL.EXE')
			Sleep(500)	
		Else
			ExitLoop
		EndIf
	Next
	While ProcessExists('EXCEL.EXE')
		ProcessClose('EXCEL.EXE')
		Sleep(500)
	WEnd
EndFunc

Func CloseOpenedExcel_()
	While ProcessExists('EXCEL.EXE')
		ProcessClose('EXCEL.EXE')
		Sleep(500)
	WEnd
EndFunc

Func Common_WiteTestCaseExecuteRecode($sTempTXTPath,$TestCase_Numbers)
	Local $file = FileOpen($sTempTXTPath, 129)
	;Check if file opened for writing OK
	If $file = -1 Then
		MsgBox(0, "Error", "Unable to open file.")
		Exit
	EndIf
	FileWrite($file,  $TestCase_Numbers & @CRLF)
	FileClose($file)
EndFunc

Func Common_WriteAutomationTestCaseIDToTempText($sTempTXTPath_,$TestCase_Numbers,$sTestCaseLevel)
	If $sTestCaseLevel = "ALL" Then   ;If the key ExecuteTestCaseLevel = all the execute all test case.
	Else
		Local $bIsExecuteTheTestCase = Common_IsExecuteTheTestCase($sExecuteTestCaseLevel,$sTestCaseLevel)    ;Judge current test case level is equal the key ExecuteTestCaseLevel in ini.
		If $bIsExecuteTheTestCase = True Then   ;equal
			
		Else
			Return @error  
		EndIf
	EndIf
	Local $file = FileOpen($sTempTXTPath_, 129)
	If $file = -1 Then
		MsgBox(0, "Error", "Unable to open file.")
		Exit
	EndIf
	FileWrite($file,  $TestCase_Numbers & @CRLF)
	FileClose($file)
	Return 1
EndFunc	

Func Common_CreateFile($sPath)
	If FileExists($sPath) Then
	FileDelete($sPath)
	Sleep(500)
	EndIf
	_FileCreate($sPath)
	Sleep(1000)
EndFunc

Func Common_ChooseMyPagemanagerFolder($hPMHandle)
	Local $hTree = ControlGetHandle($hPMHandle, "", $sTreeViewCtrInfo)	
	If $hTree <> "" Then
		Local $hItemFound = _GUICtrlTreeView_FindItem($hTree, @UserName)
		If $hItemFound <> 0 Then
			_GUICtrlTreeView_Expand($hTree,$hItemFound,True)
			Sleep(500)
			Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTree, "My Documents")
			If $hItemFound1 = 0 Then  _GUICtrlTreeView_FindItem($hTree, "Documents")
			If $hItemFound1 <> 0 Then
				_GUICtrlTreeView_Expand($hTree,$hItemFound1,True)
				Sleep(500)	
				Local $hItemFound2 = _GUICtrlTreeView_FindItem($hTree, "My PageManager")
				If $hItemFound2 <> 0 Then
				_GUICtrlTreeView_ClickItem($hTree, $hItemFound2)
				Sleep(300)
				Return 1
				EndIf
			EndIf
		EndIf
	EndIf
	Return @error
EndFunc

Func Common_IsTestCaseLevelQualified($sTestCaseLevel)   ;modify
	If $sExecuteTestCaseLevel = "ALL" Then   
		Return True
	Else
		Local $bIsExecuteTheTestCase = Common_IsExecuteTheTestCase($sExecuteTestCaseLevel,$sTestCaseLevel)  
		If $bIsExecuteTheTestCase == True Then   
			Return True
		Else
			Return False
		EndIf
	EndIf	
EndFunc

Func Common_ExecuteFunction($bIsExecuteNextFunction,$sFunctionName,$sFunctionName_)
	Local $arr[3]
	If $bIsExecuteNextFunction Then    ;Execute function.
		Local $sReturn = $sFunctionName  
		If @error Or $sReturn = 0 Then   ;Fail
			$arr[1]	= False 
			$arr[0]	= ""
			$arr[2]	= Common_OutputFunctionName($sFunctionName_)			
		Else   ;Execute function succeed.
			$arr[1]	= True 
			$arr[0]	= $sReturn
			$arr[2]	= ""			
		EndIf
	Else   ;Not Execute function.
		$arr[1]	= False    ;($bIsExecuteNextFunction) = True or False.
		$arr[0]	= ""    ;Function return value
		$arr[2] = ""    ;Error function name.
	EndIf 
	Return $arr
EndFunc

Func Common_ControlGetPos($Title, $text, $Ctrlid)
	Local $hwnd = WinGetHandle($Title, $text)
	If $hwnd = "" Then
		Return @error
	EndIf
	
	Local $tpoint = DllStructCreate("int X;int Y")
	Local $ControlPos = ControlGetPos($Title, $text, $Ctrlid)
	DllStructSetData($tpoint, "X", $ControlPos[0])
	DllStructSetData($tpoint, "Y", $ControlPos[1])
	Sleep(1000)
	_WinAPI_ClientToScreen($hwnd, $tpoint)
	Local $xy[4] = [DllStructGetData($tPoint, 'X'), DllStructGetData($tPoint, 'Y'), $ControlPos[2], $ControlPos[3]]
	If @error or $xy = 0 Then
		Return @error
	Else
		Return $xy
	EndIf
EndFunc  

Func Common_WinWaitSaveAsDlg()
	WinWaitActive("[CLASS:#32770]", "FolderView", 10)
EndFunc 

Func Common_AddAnnotation()
	Local $hWnd = WinGetHandle($sPageViwerWindowClass)
	Common_SleepTime(4)
	If $hWnd = "" Then
		Return @error
	EndIf
	Local $posPageViwerWindow = WinGetPos($hWnd)
	Common_SleepTime()
	If $bPageViewType Then
		Local $PosTaskPanel = ControlGetPos($hWnd,"",$sPageViewerTaskPanel)		
		MouseClick("left",$PosTaskPanel[0]+30,$posPageViwerWindow[1]+260)
		
		Common_SleepTime()
		MouseClick("left",$posPageViwerWindow[0]+400,$posPageViwerWindow[1]+300)
		Common_SleepTime()
		Send("!f")
		Send("b")
		Common_SleepTime(2)
		ControlClick($sPageViewerMessageTitle,"",6)
	Else
		Local $posAnnotation = ControlGetPos($hWnd,"",$sPageViewerAnnotation)
		MouseClick("left",$posAnnotation[0]+$posAnnotation[2]/2,$posAnnotation[1]+220)
		Send("{down}")
		Send("{Enter}")
		Common_SleepTime()
		MouseClick("left",$posPageViwerWindow[0]+100,$posPageViwerWindow[1]+100)
		Common_SleepTime()
		Send("!v")
		Send("s")
		Send("{right}")
		Send("{enter}")
		Common_SleepTime(2)
		ControlClick($sAllMessageTitle,"",6)
	EndIf
	Common_SleepTime(2)
EndFunc

Func Common_AddTextAnnotation()
	Local $hWnd = WinGetHandle($sPageViwerWindowClass)
	Common_SleepTime(4)
	If $hWnd = "" Then
		Return 0
	Else
		If $bPageViewType = 1 Then
			MouseClick("left",1107,220)   ;click text annotattion button.
			Common_SleepTime()
			MouseMove(715,324)   ;move to page view.
			Common_SleepTime()
			MouseClick("left",715,324)
			Common_SleepTime()
			Send("Txt adnnotation!")
			Common_SleepTime()

			;Close page viewwe and save the annotation.
			Send("!f")
			Common_SleepTime()
			Send("e")
			Common_SleepTime(2)
			Send("{enter}")
		Else
			
		EndIf
	EndIf
	Common_SleepTime()
	Return 1
EndFunc

Func DeleteDesktopFiles()
	Local $FileList=_FileListToArray(@DesktopDir)
	If @Error Then Return
	For $i = 1 to $FileList[0]
		If Not (StringInStr($FileList[$i], '.Log') Or StringInStr($FileList[$i], '.ini') Or StringInStr($FileList[$i], '.lnk')) Then
			FileDelete(@DesktopDir & '\' & $FileList[$i])
		EndIf
	Next
EndFunc

Func Common_GetThumbinalHdanle($hPMHandle, $TestCaseID, $sFunctionName)
	$h = ControlGetHandle($hPMHandle, "", $sThumbnailViewCtrInfo)
	If $h = '' Then
		Common_ClosePMWhenException()
		Common_WriteLog($sFaile & 'GetThumbinalHdanle($hPMHandle, $TestCaseID, $sFunctionName))', $TestCaseID, $sFunctionName, ' ')
		Return False
	Else
		Return $h
	EndIf
EndFunc

Func CopySamplesToMyPagemanagerFolder()
	DirRemove($PMFolder, 1)
	DirCopy('C:\AutomationTest\PM Samples',$PMFolder)
	Sleep(1500)
EndFunc

Func Common_RefreshThumbnail()
	Send('!v')
	Sleep(500)
	Send('f')
	Sleep(1000)
EndFunc

Func Common_ScrrenCaptureInPageViewer($sPerformResultPath)
	;_ScreenCapture_Capture($sPerformResultPath, 6, 4, 1064, 978, False)
	_ScreenCapture_Capture($sPerformResultPath, 6, 4, 1079, 1017, False)
EndFunc

Func Common_ExecuteStep($sStep1, $sStep2, $sStep3, $sStep4, $sRes)
	If $sStep1 <> '' And $sStep2 <>'' And $sStep3 <> '' And $sStep4 <> '' Then
		Return $sStep1 & @CRLF & $sStep2 & @CRLF & $sStep3 & @CRLF & $sStep4 & @CRLF & $sRes
	ElseIf $sStep1 <> '' And $sStep2 <>'' And $sStep3 <> '' And $sStep4 == '' Then
		Return $sStep1 & @CRLF & $sStep2 & @CRLF & $sStep3 & @CRLF & $sRes
	ElseIf $sStep1 <> '' And $sStep2 <>'' And $sStep3 == '' And $sStep4 == '' Then
		Return $sStep1 & @CRLF & $sStep2 & @CRLF & $sRes
	ElseIf $sStep1 <> '' And $sStep2 == '' And $sStep3 == '' And $sStep4 == '' Then
		Return $sStep1 & @CRLF & $sRes
	ElseIf $sStep1 == '' And $sStep2 == '' And $sStep3 == '' And $sStep4 == '' Then
		Return $sRes
	EndIf
	Return 'Error Common_ExecuteStep($sStep1, $sStep2, $sStep3, $sStep4, $sRes)'
EndFunc

Func Common_ExecuteStep_EX($sStep1, $sStep2, $sStep3, $sStep4, $sRes)
	If StringLen($sStep1) > 3 And StringLen($sStep2) > 3 And StringLen($sStep3) > 3 And StringLen($sStep4) > 3 Then
		Return $sStep1 & @CRLF & $sStep2 & @CRLF & $sStep3 & @CRLF & $sStep4 & @CRLF & $sRes
	ElseIf StringLen($sStep1) > 3 And StringLen($sStep2) > 3 And StringLen($sStep3) > 3 And StringLen($sStep4) < 3 Then
		Return $sStep1 & @CRLF & $sStep2 & @CRLF & $sStep3 & @CRLF & $sRes
	ElseIf StringLen($sStep1) > 3 And StringLen($sStep2) > 3 And StringLen($sStep3) < 3 And StringLen($sStep4) < 3 Then
		Return $sStep1 & @CRLF & $sStep2 & @CRLF & $sRes
	ElseIf StringLen($sStep1) > 3 And StringLen($sStep2) < 3 And StringLen($sStep3) < 3 And StringLen($sStep4) < 3 Then
		Return $sStep1 & @CRLF & $sRes
	ElseIf StringLen($sStep1) < 3 And StringLen($sStep2) < 3 And StringLen($sStep3) < 3 And StringLen($sStep4) < 3 Then
		Return $sRes
	EndIf
	Return 'Error Common_ExecuteStep_EX($sStep1, $sStep2, $sStep3, $sStep4, $sRes)'
EndFunc

Func Common_ExecuteStep_EX1($sStep1, $sStep2, $sStep3, $sStep4, $sRes)
	If StringLen($sStep1) > 3 And StringLen($sStep2) > 3 And StringLen($sStep3) > 3 And StringLen($sStep4) > 3 Then
		Return @CRLF & $sStep1 & @CRLF & $sStep2 & @CRLF & $sStep3 & @CRLF & $sStep4 & @CRLF & $sRes
	ElseIf StringLen($sStep1) > 3 And StringLen($sStep2) > 3 And StringLen($sStep3) > 3 And StringLen($sStep4) < 3 Then
		Return @CRLF & $sStep1 & @CRLF & $sStep2 & @CRLF & $sStep3 & @CRLF & $sRes
	ElseIf StringLen($sStep1) > 3 And StringLen($sStep2) > 3 And StringLen($sStep3) < 3 And StringLen($sStep4) < 3 Then
		Return @CRLF & $sStep1 & @CRLF & $sStep2 & @CRLF & $sRes
	ElseIf StringLen($sStep1) > 3 And StringLen($sStep2) < 3 And StringLen($sStep3) < 3 And StringLen($sStep4) < 3 Then
		Return @CRLF & $sStep1 & @CRLF & $sRes
	ElseIf StringLen($sStep1) < 3 And StringLen($sStep2) < 3 And StringLen($sStep3) < 3 And StringLen($sStep4) < 3 Then
		Return @CRLF & $sRes
	EndIf
	Return @CRLF & $sRes
EndFunc

Func Common_SetSaveAsFormat($Format)
	ControlClick("[CLASS:#32770]", "FolderView", 1136)
	Sleep(500)
	Switch $Format   
	Case "BMP(*.BMP)"
		Send("b")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "JPEG(*.JPG)"
		Send("b")
		Sleep(200)		
		Send("j")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PaintBrush(*.PCX)"
		Send("b")
		Sleep(200)		
		Send("p")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-uncompressed(*.TIF)"
		Send("b")
		Sleep(200)	
		Send("t")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-packbits(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 1
			Send("t")
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-G3 compression(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 2
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-G4 compression(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 3
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "TIFF-multiple page(*.TIF)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 4
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "JPEG(*.JPG)"
		Send("b")
		Sleep(200)	
		Send("j")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PICT(*.PCT)"
		Send("b")
		Sleep(200)	
		Send("p")
		Sleep(200)	
		Send("p")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Targa(*.TGA)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 5
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Targa-rle(*.TGA)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 6
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "PNG(*.PNG)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 2
			Send("p")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Photoshop(*.PSD)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 3
			Send("p")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "GIF(*.GIF)"
		Send("b")
		Sleep(200)	
		Send("g")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Text(*.TXT)"
		Send("b")
		Sleep(200)	
		For $i = 0 to 7
			Send("t")
			Sleep(150)
		Next
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "Rich Text Format(*.RTF)"
		Send("b")
		Sleep(200)	
		Send("r")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "HTML(*.HTM)"
		Send("b")
		Sleep(200)	
		Send("h")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)
	Case "XPS File(*.xps)"
		Send("b")
		Sleep(200)	
		Send("x")
		Sleep(200)
		Send("{ENTER}")
		Sleep(500)		
	EndSwitch
EndFunc

Func Common_GetSaveAsFormat($Format)
	If StringInStr($Format, 'bmp') Then
		Return '.bmp'
	ElseIf StringInStr($Format, 'jpg') Then
		Return '.jpg'
	ElseIf StringInStr($Format, 'pcx') Then
		Return '.pcx'		
	ElseIf StringInStr($Format, 'tif') Then
		Return '.tif'			
	ElseIf StringInStr($Format, 'pct') Then
		Return '.pct'	
	ElseIf StringInStr($Format, 'tga') Then
		Return '.tga'	
	ElseIf StringInStr($Format, 'png') Then
		Return '.png'	
	ElseIf StringInStr($Format, 'psd') Then
		Return '.psd'
	ElseIf StringInStr($Format, 'gif') Then
		Return '.gif'
	ElseIf StringInStr($Format, 'txt') Then
		Return '.txt'
	ElseIf StringInStr($Format, 'rtf') Then
		Return '.rtf'
	ElseIf StringInStr($Format, 'htm') Then
		Return '.htm'
	ElseIf StringInStr($Format, 'xps') Then
		Return '.xps'
	EndIf
EndFunc

Func Common_UnselectDateColumnInListView_($PMTitle)
	; Unselect "Date Modified" and "Date create" in list view.
	Local $size = WinGetPos($PMTitle)   ;Get PM window postion and size.
	If $size <> 0 Then
		If MouseClick("right", $size[2] / 2.48, $size[3] / 11.35) Then
			Sleep(500)
			For $i = 0 to 4 
				Send("{DOWN}")
			Next
			Send("{ENTER}")
			Sleep(500)	
			If MouseClick("right", $size[2] / 2.48, $size[3] / 11.35) Then
				Sleep(500)	
				For $i = 0 to 5 
					Send("{DOWN}")
				Next
				Send("{ENTER}")
				Sleep(500)
			EndIf
		EndIf	
	EndIf
	Return @error
EndFunc

Func Common_UnselectDateColumnInListView($PMTitle)
	; Unselect "Date Modified" and "Date create" in list view.
	Local $size = WinGetPos($PMTitle)   ;Get PM window postion and size.
	If $size <> 0 Then
		If MouseClick("right", $size[2] / 2.48, $size[3] / 11.35) Then
			Sleep(500)
			For $i = 0 to 4 
				Send("{DOWN}")
			Next
			Send("{ENTER}")
			Sleep(500)	
			If MouseClick("right", $size[2] / 2.48, $size[3] / 11.35) Then
				Sleep(500)	
				For $i = 0 to 5 
					Send("{DOWN}")
				Next
				Send("{ENTER}")
				Sleep(500)
			EndIf
			If MouseClick("right", $size[2] / 2.48, $size[3] / 11.35) Then
				Sleep(500)	
				For $i = 0 to 6 
					Send("{DOWN}")
				Next
				Send("{ENTER}")
				Sleep(500)
				Return 1
			EndIf
		EndIf	
	EndIf
	Return @error
EndFunc
